import { request } from '@/utils/request'

const base = '/views'

export function findPages () {
  return request({
    url: `${base}/pages`,
    method: 'get'
  })
}

export function deletePage (pageCode) {
  return request({
    url: `${base}/pages/${pageCode}`,
    method: 'delete'
  })
}

export function addPage (data) {
  return request({
    url: `${base}/pages`,
    method: 'post',
    data
  })
}

export function updatePage (data) {
  return request({
    url: `${base}/pages/${data.code}`,
    method: 'patch',
    data
  })
}

export function addButton (data) {
  return request({
    url: `${base}/buttons`,
    method: 'post',
    data
  })
}
export function deleteButton (buttonCode) {
  return request({
    url: `${base}/buttons/${buttonCode}`,
    method: 'delete'
  })
}

// ----------------


export function updatePagePermissions (pagePermissions) {
  return request({
    url: `${base}/pages`,
    method: 'patch',
    data: pagePermissions
  })
}

export function findAllPagesCodes () {
  return request({
    url: `${base}/pages/codes`,
    method: 'get'
  })
}

export function findAllButtons () {
  return request({
    url: `${base}/buttons`,
    method: 'get'
  })
}

export function findButtonsByPageName (routeName) {
  return request({
    url: `${base}/pages/${routeName}/buttons`,
    method: 'get'
  })
}





export function updateButton (code, name) {
  return request({
    url: `${base}/buttons/${code}`,
    method: 'patch',
    data: {
      name: name
    }
  })
}
